#define __STDC_VERSION__ 201112L
#include "process.h"
#include<string.h>
#include<unistd.h>
#include<stdio.h>


#define NUM 101
#define STYLE '*'
#define POINT '.'
#define SPACE ' '

const int pnum = 6;

void FulshProcess(double total, double current)
{
  //更新当前进度的百分比
  double rate = (current/total)*100;

  //更新进度条主体
  char bar[NUM];
  memset(bar,'\0',sizeof(bar));
  for(int i = 0; i < (int)rate; i++)
  {
    bar[i] = STYLE;
  }

  //更新旋转光标
  static int num = 0;
  num++;
  num%=pnum;

  char points[pnum+1];
  memset(points,'\0',sizeof(points));
  for(int i = 0; i < pnum; i++)
  {
    if(i<num) points[i] = POINT;
    else points[i] = SPACE;
  }

  printf("[%-100s][%.1lf%%]%s\r",bar,rate,points);
  fflush(stdout);
}

//void process()
//{
// // printf("process");
//   const char* lable = "|/-\\";
//   int len = strlen(lable);
//   char bar[NUM];
//   memset(bar,'\0',sizeof(bar));
//   int count = 0;
//   while(count<=100)
//   {
//     printf("[%-100s][%d%%][%c]\r",bar,count,lable[count%len]);
//     fflush(stdout);
//     bar[count]=STYLE;
//     count++;
//     if(count == NUM)
//     {
//       bar[count-1] = '\0';
//       break;
//     }
//     usleep(50000);
//   }
//   printf("\n");
//}
